package com.example.yqzs.util;

import java.util.Random;
import java.util.UUID;

/**
 * UUID工具类
 * @author geekcattle
 */
public class UuidUtil {
    /**
     * 获得一个UUID
     *
     * @return String UUID
     */
    public static String getUUID() {
        return UUID.randomUUID().toString().replace("-", "").toLowerCase();
    }

    /**
     * 获得指定数目的UUID
     *
     * @param number int 需要获得的UUID数量
     * @return String[] UUID数组
     */
    public static String[] getUUID(int number) {
        if (number < 1) {
            return null;
        }
        String[] ss = new String[number];
        for (int i = 0; i < number; i++) {
            ss[i] = getUUID();
        }
        return ss;
    }

    private static Random r = new Random();
    private static String ssource = "0123456789";
    private static char[] src = ssource.toCharArray();

    //产生随机字符串
    private static String randString (int length) {
        char[] buf = new char[length];
        int rnd;
        for(int i = 0; i < length; i++) {
            rnd = Math.abs(r.nextInt()) % src.length;
            buf[i] = src[rnd];
        }
        return new String(buf);
    }

    //调用该方法，产生随机字符串,
    //参数i: 为字符串的长度
    public static String runVerifyCode(int i) {
        String VerifyCode = randString(i);
        return VerifyCode;
    }
}
